package org.anyin.gitee.cloud.lib.core.web.context;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class WebContext {

    private static ThreadLocal<HttpServletRequest> requestHolder = new ThreadLocal();
    private static ThreadLocal<HttpServletResponse> responseHolder = new ThreadLocal();

    public WebContext() {
    }

    public static void init(HttpServletRequest request, HttpServletResponse response) {
        requestHolder.set(request);
        responseHolder.set(response);
    }

    public static void destroy() {
        requestHolder.remove();
        responseHolder.remove();
    }

    public static HttpServletRequest getRequest() {
        return requestHolder.get();
    }

    public static HttpServletResponse getResponse() {
        return responseHolder.get();
    }
}
